package com.ruoyi.my.service.impl;

import com.ruoyi.my.domain.MySectionProject;
import com.ruoyi.my.mapper.MySectionProjectMapper;
import com.ruoyi.my.service.MySectionProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MySectionProjectServiceImpl implements MySectionProjectService {

    @Autowired
    MySectionProjectMapper mySectionProjectMapper;

    @Override
    public List<MySectionProject> selectMySectionProjectList() {
        return mySectionProjectMapper.selectList(null);
    }

    @Override
    public List<MySectionProject> selectMySectionProjectListBymenu(String menu, String menuName) {
        Map<String,Object> colmap = new HashMap<>();
        colmap.put("menu",menu);
        colmap.put("menu_name",menuName);
        return mySectionProjectMapper.selectByMap(colmap);
    }

    @Override
    public String remove(Integer id) {
        try {
            mySectionProjectMapper.deleteById(id);
            return "删除成功！";
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @Override
    public String add(MySectionProject mySectionProject) {
        try {
            mySectionProjectMapper.insert(mySectionProject);
            return "添加成功！";
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @Override
    public String update(MySectionProject mySectionProject) {
        try {
            MySectionProject sectionProject = mySectionProjectMapper.selectById(mySectionProject.getId());
            if (sectionProject.getMenu().equals(mySectionProject.getMenu())){
                return "修改失败，无权限修改主菜单名！";
            }else if(sectionProject.getMenuName().equals(mySectionProject.getMenuName())){
                return "修改失败，无权限修改子菜单名！";
            }
            mySectionProjectMapper.updateById(mySectionProject);
            return "修改成功！";
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
